<template>
	<view class="tab-row">
		<scroll-view class="tab-row-scroll" :scroll-x="true">
			<view class="tab-row-list">
				<view class="tab-row-item" v-for="(item, index) in menus" :key="index" @tap="onTapItem(index)">
					<view :class="['tab-row-item-text', currentIndex == index ? 'tab-row-item-text-active' : '']">
						{{ item }}
					</view>
					<view :class="['tab-row-item-line', currentIndex == index ? 'tab-row-item-line-active' : '']">
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>
<script setup lang="ts">
	import { ref } from 'vue';

	defineProps({
		menus: {
			type: Array<String>,
			default: [],
		},
	})
	const emits = defineEmits(['change',])
	const currentIndex = ref(0)
	const onTapItem = (index : number) => {
		currentIndex.value = index
		emits('change', index);
	}
</script>
<style lang="scss">
	.tab-row {
		// position: sticky;
		// top: 0px;
		// left: 0px;
		display: flex;
		height: var(--tabs-height);
		line-height: var(--tabs-height);
		background-color: white;

		&-scroll {
			overflow-x: auto;
			overflow-y: hidden;
			width: 100%;
		}

		&-list {
			flex-shrink: 0;
			display: flex;
			width: 100%;
			height: 100%;
		}

		&-item {
			flex: 1;
			display: inline-flex;
			flex-direction: column;
			justify-content: space-evenly;
			align-items: center;
			box-sizing: border-box;
			min-width: 50px;
			margin-left: 10px;
			margin-right: 10px;

			&-text {
				font-size: 14px;
				color: var(--color-normal);
				font-style: normal;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;

				&-active {
					color: #000000;
					font-weight: 600;
					font-size: 16px;
				}
			}

			&-line {
				content: " ";
				width: 0;
				height: 3px;
				background-color: var(--primary-color);

				&-active {
					width: 50%;
				}
			}
		}
	}
</style>